import os,sys
import shutil


dir=r'Y:/bfdefect/11-08-162046'


def rename():
    for i in os.listdir(dir):
        
        # temp=f'{dir}/{i}'
        # print(temp,os.path.basename(temp))
        # temp=i.replace(i.rindex('-'),'@')
        # print(i,i.rindex('-'),i[0:i.rindex('-')]+'@'+i[5:])

        idx=i.rindex('@')
        newName=f'{i[0:idx]}_{i[idx+1:]}'
        print(i,idx,newName)

        shutil.move(f'{dir}/{i}',f'{dir}/{newName}')


def genFileList():
    
    x=[i for i in range(-14,15,1)]
    y=[i for i in range(-11,12,1)]
    c=[i for i in range(15)]
    os.chdir(dir)
    print(len(os.listdir()))
    with open(f'd:/cf.txt','w') as f:
        for i in x:
            for j in y:
                for k in c:
                    tn=f'{dir}/{i}_{j}_{k}.jpg'
                    tx=f'{i}_{j}_{k}.jpg'
                    if os.path.exists(tn):
                        f.write(f'{tx}\n')
                        pass

def GetGlobalPos(data:list):
    # print(data)
    cx=(-2346.06,-1959.42)
    dieSize=(5000,6000)
    # return (data[0],(data[3]*dieSize[0]+data[1]+cx[0],data[4]*dieSize[1]+data[2]+cx[1]))
    return [data[0],data[3]*dieSize[0] + data[1] + cx[0],data[4]*dieSize[1] + data[2] + cx[1]]


def GenPosFile(srcPath:str,dstPath:str):
    with open(dstPath,'w') as d:
        with open(srcPath,'r') as s:
            for line in s:
                if len(line.strip())>0:
                    arr=line.strip().split(' ')[0:5]
                    print(arr)
                    arrs=[int(arr[0])]
                    arrs1=[float(x) for x in arr[1:]]
                    arrs.extend(arrs1)

                    arrd=GetGlobalPos(arrs)
                    temp=[str(x) for x in arrd]
                    d.write(f'{' '.join(temp)}\n')


def GetDiePoint(srcPath:str):
    dict={}
    with open(srcPath,'r') as s:
        for line in s:
            if len(line.strip())>0:
                temp=line.strip().split(' ')
                if len(temp)==4:
                    dict[(int(temp[0]),int(temp[1]))]=[float(temp[2]),float(temp[3])]
                    pass

    return dict


def GenPosFile1(srcPath:str,dstPath:str):
    zz=GetDiePoint('d:/diepos.txt')
    with open(dstPath,'w') as d:
        with open(srcPath,'r') as s:
            for line in s:
                if len(line.strip())>0:
                    arr=line.strip().split(' ')[0:5]
                    print(arr)
                    arrs=[int(arr[0])]
                    arrs1=[float(x) for x in arr[1:]]
                    arrs.extend(arrs1)

                    die=(arrs[3],arrs[4])

                    arrd=[arrs[0],zz[die][0]+arrs[1],zz[die][1]+arrs[2]]
                    # arrd.extend(zz[die])

                    temp=[str(x) for x in arrd]
                    d.write(f'{' '.join(temp)}\n')






GenPosFile1(r'y:\cf_final.txt',r'y:\cf_pos.txt')
# GenPosFile('d:/20251110/31.txt','d:/31.txt')



# genFileList()

print('ok')
            


    

    
    
    

    
